#ifndef SENSORTRAYCONVEYERCONFIG_H
#define SENSORTRAYCONVEYERCONFIG_H

#include "BasicElement/scaxis.h"
#include "configManager/configobject.h"

class SensorTrayConveyerConfig : public ConfigObject
{
    Q_OBJECT

    Q_PROPERTY(QString beltRunDirection READ beltRunDirection WRITE setBeltRunDirection NOTIFY beltRunDirectionChanged)
    Q_PROPERTY(
        int pushOutTrayTimeout READ pushOutTrayTimeout WRITE setPushOutTrayTimeout NOTIFY pushOutTrayTimeoutChanged)
    Q_PROPERTY(int delayAfterPushoutTray READ delayAfterPushoutTray WRITE setDelayAfterPushoutTray NOTIFY delayAfterPushoutTrayChanged)
    Q_PROPERTY(int detectHasTrayMaxTime READ detectHasTrayMaxTime WRITE setDetectHasTrayMaxTime NOTIFY
                   detectHasTrayMaxTimeChanged)

public:
    SensorTrayConveyerConfig(QObject *parent = nullptr) : ConfigObject(parent)
    {
        setOptionalProperty("beltRunDirection", toVariantList(SCAxis::DirEnumInfo().names()));
        init();
    }

    QString beltRunDirection() const
    {
        return m_beltRunDirection;
    }

    int pushOutTrayTimeout() const
    {
        return m_pushOutTrayTimeout;
    }

    int detectHasTrayMaxTime() const
    {
        return m_detectHasTrayMaxTime;
    }

    int delayAfterPushoutTray() const
    {
        return m_delayAfterPushoutTray;
    }

public slots:
    void setBeltRunDirection(QString beltRunDirection)
    {
        if (m_beltRunDirection == beltRunDirection)
            return;

        m_beltRunDirection = beltRunDirection;
        emit beltRunDirectionChanged(m_beltRunDirection);
    }

    void setPushOutTrayTimeout(int pushOutTrayTimeout)
    {
        if (m_pushOutTrayTimeout == pushOutTrayTimeout)
            return;

        m_pushOutTrayTimeout = pushOutTrayTimeout;
        emit pushOutTrayTimeoutChanged(m_pushOutTrayTimeout);
    }

    void setDetectHasTrayMaxTime(int detectHasTrayMaxTime)
    {
        if (m_detectHasTrayMaxTime == detectHasTrayMaxTime)
            return;

        m_detectHasTrayMaxTime = detectHasTrayMaxTime;
        emit detectHasTrayMaxTimeChanged(m_detectHasTrayMaxTime);
    }

    void setDelayAfterPushoutTray(int delayAfterPushoutTray)
    {
        if (m_delayAfterPushoutTray == delayAfterPushoutTray)
            return;

        m_delayAfterPushoutTray = delayAfterPushoutTray;
        emit delayAfterPushoutTrayChanged(m_delayAfterPushoutTray);
    }

signals:
    void beltRunDirectionChanged(QString beltRunDirection);

    void pushOutTrayTimeoutChanged(int pushOutTrayTimeout);

    void detectHasTrayMaxTimeChanged(int detectHasTrayMaxTime);

    void delayAfterPushoutTrayChanged(int delayAfterPushoutTray);

private:
    QString m_beltRunDirection;
    int m_pushOutTrayTimeout = 30000;
    int m_detectHasTrayMaxTime = 1000;
    int m_delayAfterPushoutTray = 200;
};

#endif    // SENSORTRAYCONVEYERCONFIG_H
